(Logo)  Programming in JavaScript

Learning JavaScript

An overview of JavaScript falls outside the scope of this manual. For more information, search the web for an explanatory page you like, or look at NetScape's JavaScript 1.1 guide.

AWebJS

AWebJS is a standalone JavaScript interpreter, to facilitate testing of your JavaScript programs that doesn't rely on browser objects.

Starting from the shell

You can run AWebJS only from the Shell (or CLI).
Format:
AWebJS filename... [ PUBSCREEN public_screen_name ] [ DEBUG ]

Template:
FILES/M/A,PUBSCREEN/K,DEBUG/S
The files in the FILES argument are executed in the given order, using a shared variable space. That is, global variables and functions defined in one file are still available in later files (during the same invocation of AWebJS).

The screen name in the PUBSCREEN argument is used to open any error requesters on, and the debugger window. By default these windows are opened on the default public screen.

If you set the DEBUG switch, the debugger is started when executing each file.

Special functions

When a program is run using AWebJS, the browser objects like document and window are not available. Because it wouldn't make much sense to run a program without any input or output facilities, AWebJS defines a couple of predefined I/O functions.

write, writeln

Writes one or more expressions to the standard output stream (the Shell window).
Syntax
write(expression1 [,expression2], ...[,expressionN])
writeln(expression1 [,expression2], ...[,expressionN])
Parameters
expression1 through expressionN are any JavaScript expressions.
Description
The write function converts each expression to string, and outputs the result to the standard output stream. Usually this will be the shell window, unless you have redirected the output of AWebJS.

The writeln function does the same as the write function, but adds a newline after the last expression.

When you want to include your JavaScript program in an HTML document, you'll have to use document.write instead of just write. To avoid the need of changing your program again after you've completed testing with AWebJS, use the following code fragment:

function Document()
{  this.write=write;
   this.writeln=writeln;
}

var document=new Document();

Add these lines to the start of your program (and remove them before including the JavaScript program in your HTML document). Or save these lines in a separate file and specify the file as the first FILES argument on the AWebJS call.

By using this code fragment, you can use document.write and document.writeln in your JavaScript program even when testing with AWebJS.

readln

Reads a line from the standard input stream (the Shell window).
Syntax
readln()
Description
The readln function reads a line from the standard input stream and returns it as a string value. Usually the standard input stream will be the shell window, unless you have redirected the input of AWebJS.

The string returned has a maximum length of 80 characters.

JavaScript debugger

The built-in JavaScript debugger facilitates in adding JavaScript functions to your own HTML pages. You can step through any script, and investigate variable values.

Invocation

You can invoke the debugger in two ways:

To start the debugger with every piece of JavaScript executed, you check the Control / Debug JavaScript menu option.

Alternatively, you can select the Debug button from a run-time JavaScript error requester to invoke the debugger.

Functions

When the debugger is active, the program is executed step by step. You can control how big these steps are.

In the top region of the debugger window, the current line number and the current code fragment is shown. "Code fragment" can be anything: a statement, a partial expression, or even an entire function. Note the code shown here is a result of decompilation, so it may look a bit different from the actual source code.

You control what is done next by clicking one button in the button row.
Over Step over the current fragment.
The current fragment is executed, and execution is halted again afterwards.
Into Step into the current fragment.
The first part of the current fragment is made the new current fragment. For example, if the current fragment is a compound statement (between braces, {...}), the first contained statement will become the next current fragment. If the current fragment is an assignment statement, the operand on the left-hand side of the assignment operator is made the next current fragment.

Note: If the current fragment is atomic (like a number, or an identifier), execution is advanced one step.

Test Test the current fragment.
The current fragment is executed, but execution is not advanced. The result of the current fragment is shown in the result field at the bottom of the debugger window.

Note: this function has side effects! If the value of a variable is changed in the current fragment (like the = or the ++ operators), this change is permanent.

Run Run the program. The debugger window is closed, and execution is resumed without further interruption.
Stop Stop the program. The debugger window is closed and execution is cancelled.
Below the button row is a text entry field labelled Expression. You can type any expression in this field. When you hit Enter the expression is evaluated and the result is shown in the result field at the bottom of the window. Note: this function has side effects! If the value of a variable is changed in the current fragment (like the = or the ++ operators), this change is permanent.


<- Back to index.